//
//  BKHttpRequestCache.m
//  iLookForiPad
//
//  Created by baboy on 13-2-28.
//  Copyright (c) 2013年 baboy. All rights reserved.
//


#import "BKHttpRequestCachePolicy.h"
#import "BKKitDefines.h"
#import "NSString+x.h"
#import "FileCache.h"

#define HTTP_CACHE_FILE(fn) getStorageFilePath(fn, NETWORK_CACHE_DIR)

NSString * getHttpRequestCacheFilePath(NSURL *url) {
    NSString *fn = [[url absoluteString] md5];
    NSString *ext = [url pathExtension];
    if ([ext length]==0) {
        ext = @"tmp";
    }
    NSString *cacheFn = [NSString stringWithFormat:@"%@.%@",fn,ext];
    NSString *fp = HTTP_CACHE_FILE(cacheFn);
    return fp;
}
NSData * getHttpRequestCacheFileData(NSURL *url){
    NSString *fp = getHttpRequestCacheFilePath(url);
    if (fp && [[NSFileManager defaultManager] fileExistsAtPath:fp]) {
        return [NSData dataWithContentsOfFile:fp];
    }
    return nil;
}
